package com.edu.edu.week_project01.activity.adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.edu.edu.week_project01.R;
import com.edu.edu.week_project01.activity.bean.ProgrameDetailBean;

import java.util.List;

/**
 * Created by Administrator on 10/13 0013.
 */
public class ProgrameDetailAdapter extends BaseAdapter{


    private List<ProgrameDetailBean.DataBean> mlist;

    public ProgrameDetailAdapter(List<ProgrameDetailBean.DataBean> list){
        this.mlist = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mlist != null ? mlist.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mlist != null ? mlist.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertview, ViewGroup parent) {
        ViewHolder holder;
        if(convertview == null){
            convertview = LayoutInflater.from(parent.getContext()).inflate(R.layout.total_list_item,parent,false);
            holder = new ViewHolder(convertview);
            convertview.setTag(holder);
        }else{
            holder = (ViewHolder) convertview.getTag();
        }
        //绑定数据
        ProgrameDetailBean.DataBean dataBean = mlist.get(position);
        holder.total_tv_nick.setText(dataBean.getNick());
        Log.i("TAG",">>>>>>>>>>>>>>>>>>>>>>newUrl=" + dataBean.getTitle());
        holder.total_tv_title.setText(dataBean.getTitle());
        holder.total_tv_view.setText(dataBean.getView());
        String total_iv_thumb = dataBean.getThumb();
        String total_iv_avator = dataBean.getAvatar();
        //利用glide缓存图片
        Glide.with(parent.getContext()).load(total_iv_thumb).placeholder(R.mipmap.ic_launcher).into(holder.total_iv_thumb);
        Glide.with(parent.getContext()).load(total_iv_avator).placeholder(R.mipmap.ic_launcher).into(holder.total_iv_avator);
        return convertview;
    }
    class ViewHolder{
        ImageView total_iv_thumb,total_iv_avator;
        TextView total_tv_view,total_tv_nick,total_tv_title;
        public ViewHolder(View convertview){
            total_iv_thumb = (ImageView) convertview.findViewById(R.id.total_iv_thumb);
            total_iv_avator = (ImageView) convertview.findViewById(R.id.total_iv_avator);
            total_tv_view = (TextView) convertview.findViewById(R.id.total_tv_view);
            total_tv_nick = (TextView) convertview.findViewById(R.id.total_tv_nick);
            total_tv_title = (TextView) convertview.findViewById(R.id.total_tv_title);
        }
    }
}
